home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / AMOSList / AMOSLIST / text0164.txt < prev    next >
Encoding:
Text File  |  1998-04-01  |  3.6 KB  |  141 lines

  1. On Sunday 15-Mar-98 at 23:35:14, a nutter named Jonas Thorell
  2. had wet pants when they typed about `Textfile parsing'.
  3. >Okay,  see if someone can help me out here. What I want is to take an
  4. >ordinary textfile and process in certain ways.
  5.  
  6. >1. Determine how many lines of text it is in it. How?
  7. >2. Use the above value making a for-loop like
  8.  
  9. >For a=1 to <the value mentioned>
  10. >grab one line of text and insert it in t$(a)
  11.  
  12.  
  13. Hiya Jonas,
  14.  
  15. Here  is  a  nice  bit of code which I have been using for a long long
  16. time in many disk mag coded productions (eg. DMC, BTF etc).
  17.  
  18. Simply  cut  this  out  and use the Merge ASCII option to load it into
  19. Amos to fiddle about with it...enjoy.
  20.  
  21.  
  22. <SNIP HERE>
  23. '
  24. ' ***************************************
  25. '
  26. ' Load and process a text file easily :) 
  27. ' bY Andy Gibson 
  28. '
  29. ' I hope this helps you out Jonas....
  30. '
  31. ' ***************************************
  32. '
  33. ' Depending on the size of your file, you may need to UP this value... 
  34. Set Buffer 40
  35. '
  36. ' LINES must be global here... 
  37. Global TXT$,LINES
  38. '
  39. ' Enter your text file's full path here... 
  40. Proc _LOAD_TXT["dev:dir/file"]
  41. '
  42. '
  43. ' Now we can use a Dim with the correct amount of lines to hold
  44. ' each line in there...
  45. Dim TXT$(LINES)
  46. Global TXT$()
  47. '
  48. ' Simply sort the lines into the Global Dim here...
  49. Proc _SORT_FILE
  50. '
  51. '
  52. ' Now you can easily read any line of the text held in the array 
  53. ' TXT$().
  54. '
  55. '
  56. ' Procedure are here...
  57. '
  58. Procedure _LOAD_TXT[TXT$]
  59.    '
  60.    ' This Proc will work out how many lines are in your file. 
  61.    ' Checks for normal Chr$(10) RETURN code. You could alter
  62.    ' it to Chr$(13) for PC text files if need be....
  63.    '
  64.    ' Amcaf only.... (no need to use Open in etc...) 
  65.    ' Dload TXT$,17  
  66.    '
  67.    '
  68.    ' Amos normal way... 
  69.    Open In 1,TXT$
  70.    L=Lof(1) : Close 1
  71.    Reserve As Data 7,L
  72.    Bload CF$,7
  73.    '
  74.    '
  75.    ' Read Lines...
  76.    POS=Start(7) : LINES=0
  77.    '
  78.    Do 
  79.       Exit If POS>=Bank End(7)
  80.       LINES1=Hunt(POS To Bank End(7),Chr$(10))
  81.       '
  82.       ' Wanna see the text...
  83.       A$=Peek$(POS,POS-LINE,Chr$(10))
  84.       Print A$
  85.       '
  86.       Exit If LINE=Bank End(7) or LINE=0
  87.       POS=LINE+1
  88.       Inc LINES
  89.    Loop 
  90.    '
  91.    ' One other point to note, the Bank End command is not an normal 
  92.    ' Amos Pro one! And I can't remember which Ext I have installed
  93.    ' which uses it! If this code doesn't funtion properly in your 
  94.    ' interpreter, simply change the Bank End commands to summat 
  95.    ' more suitable like Start(bnk)+start(bnk) to Length(bnk)
  96.    '
  97. End Proc
  98. Procedure _SORT_FILE
  99.    '
  100.    ' Hold each line of text in the array...easy or what?
  101.    '
  102.    POS=Start(7)
  103.    '
  104.    For I=0 To LINES
  105.       A$=Peek$(POS,Bank End(7),Chr$(10))
  106.       If A$>""
  107.          TXT$(I)=Peek$(POS,Bank End(7),Chr$(10))
  108.          Add POS,Len(TXT$(I))+1
  109.       Else 
  110.          Inc POS
  111.       End If 
  112.    Next I
  113.    '
  114.    ' No more need to hold the file in a mem bank, so erase it...
  115.    '
  116.    Erase 7
  117.    '
  118. End Proc
  119.  
  120.  
  121. <SNIP>
  122.  
  123. Onbiosuly  you could also do more to this such as adding pages and the
  124. likes, but I'll leave you to easily work that one out :)
  125.  
  126. Tarra for now....Andy Gibson
  127.  
  128. -- 
  129. *****************************************************************
  130. *_______/\_____/\_______/\_____/\                               *
  131. *\       /\  ___/\       /\  ___/ Andy Gibson <---------------- *
  132. * \_/\  / /\/|  _ \_/\  /  \/ \   ----------> aka SKiDZ/Area 51 *
  133. * / _/ / /   |_| // _/ /  __\  \                                *
  134. * \// /  \___   / \// /  /__   /    andy@agasinc.demon.co.uk    *
  135. *  /_/       \_/   /_/      \_/      <-=-=-=-=-=-=-=-=-=->      *
  136. *         pRODUCTiONS 9T8                                       *
  137. *****************************************************************
  138.  
  139.  
  140.  
  141.